using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MyCollections.Model;
using ImdbServices;

namespace MyCollections.Forms
{
    public partial class fMovie : Form
    {
        private MovieCollection movie = new MovieCollection();
        private MovieCollection movie_aux = new MovieCollection();

        public fMovie()
        {
            InitializeComponent();
        }

        public fMovie(MovieCollection movie_)
            : this()
        {
            this.movie = movie_;
            this.movie_aux = movie_;
            LoadMovie(movie_);
        }

        public fMovie(MovieCollection movie_, fMain parent)
            : this()
        {
            //this.movie = movie_;
            //this.movie_aux = movie_;
            this.MdiParent = parent;
            LoadMovie(movie_);            
        }

        private void LoadMovie(MovieCollection movie)
        {
            this.tb_title.Text = movie.Title.ToString();

            this.tb_year.Text = movie.Year.ToString();

            this.tb_userrating.Text = movie.Rating.ToString();

            foreach (Person director in movie.Directors)
            {
                this.lb_directors.Items.Add(director.Name);
            }

            foreach (Person writers in movie.Writers)
            {
                this.lb_writers.Items.Add(writers.Name);
            }

            foreach (string genre in movie.Genres)
            {
                this.tb_genre.Text += genre + "; ";
            }

            //foreach (string awards in this.movie)
            //{
            //    this.tb_awards.Text += awards;
            //}

            this.tb_tagline.Text = movie.Tagline;

            // todo: plots

            foreach (Person actor in movie.Actors)
            {
                this.lb_cast.Items.Add(actor.Name);
            }

            this.thumbnail.BackgroundImage = (Image)movie.Image.Clone();
        }

        private void bt_save_Click(object sender, EventArgs e)
        {
            // save object
            this.movie = movie_aux;

            // close dialog
            DialogResult = DialogResult.OK;
            this.Dispose();
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            // save object
            this.movie = null;

            DialogResult = DialogResult.Cancel;
            this.Dispose();
        }

        #region GETs and SETs
        public MovieCollection Movie
        {
            get { return movie; }
        }
        #endregion

        #region EVENTS (update object Movie)
        private void tb_title_TextChanged(object sender, EventArgs e)
        {
            this.movie_aux.Title = this.tb_title.Text;
            this.movie_aux.Validate = false;
        }
        #endregion
    }
}